
angular.module('imsApp').factory('AdvertisersManager', ['$http', 'api','paramsManager', function ($http,api, paramsManager) {
    var AdvertisersManager = {
        /**
         * 获取广告主列表
         params:[pageNo,pageSize]//顺序不能错
         query :{keyword:xxx}
         */
        advertisersList: function (params, query) {
            return $http.get(api+'/ims/advertisers/' + paramsManager.params(params) + paramsManager.query(query)).then(function (result) {
                return result;
            });
        },
        /**
         *
         * @param advId
         * @param {userName:"xxxx"}
         * @returns {*}
         */
        advertisersResetPassword: function (advId, params) {
            return $http.put(api+'/ims/advertisers/'+advId+'/password',params).then(function (result) {
                return result;
            });
        },
        /**
         *广告主添加
         * @param params
         * @returns {"c":"s","advertiserId":1}?{"c":"f", "i":"添加失败"}
         */
        advertisersAdd: function (params) {
            return $http.post(api+'/ims/advertisers', params).then(function (result) {
                return result;
            });
        },
        /**
         *广告主详情
         * @param advertiserId
         * @returns {"c":"s","advertiserId":1}
         */
        advertisersDetail: function (advertiserId) {
            return $http.get(api+'/ims/advertisers/'+advertiserId).then(function (result) {
                return result;
            });
        },
        /**
         *广告主修改
         * @param params
         * @returns {"c":"f"} ?{"c": "f","i":"修改失败"}
         */

        advertisersEdit: function (advertiserId ,params) {
            return $http.put(api+'/ims/advertisers/'+ advertiserId , params).then(function (result) {
                return result;
            });
        },
        /**
         *广告主状态修改
         * @param params advertiserId,{status:11}
         * @returns {"c":"f"} ?{"c": "f","i":"修改失败"}
         */
        advertisersStatusEdit: function (advertiserId, params) {
            return $http.put(api+'/ims/advertisers/' + advertiserId + '/status', params).then(function (result) {
                return result;
            });
        },
        /**
         *检查广告主是否重名
         * @param params
         * @returns
         */
        advertisersCheckUsername: function (params) {
            return $http.post(api+'/ims/advertisers/checkUsername',params).then(function (result) {
                console.log(result);
                return result;
            });
        },
        /**
         *检查简称是否重名
         * @param params
         * @returns
         */
        advertisersCheckShortName: function (shortName) {
            return $http.post(api+'/ims/advertisers/checkShortName',{shortName:shortName}).then(function (result) {
                return result;
            });
        },
         //获取简单的广告主列表只有id和name
        advertiserSimpleList:function(params){
            return $http.get(api+'/ims/simple/advertisers/'+paramsManager.params(params)).then(function (result) {
                return result;
            });

        },
        /**
         *广告主删除
         * @param
         */
        advertisersDelete: function (ids) {
            return $http.delete(api+'/ims/advertisers/'+ids.join(",")).then(function (result) {
                return result;
            });
        }

    }
    return AdvertisersManager;
}]);
